package com.kun.framework.core.enums;

import com.kun.framework.core.AbstractApplication;
import com.kun.framework.core.compoment.PopupMessage;
import com.kun.framework.core.exception.AbstractPopupException;

import java.util.Optional;
import java.util.function.BiConsumer;

/**
 * 弹窗提示类型
 *
 * @author gzc
 * @since 2024/9/24
 **/
public enum PopupMessageTypeEnum {
    /**
     * 弹窗提示类型
     */
    SUCCESS("成功", (t, e) -> {
        PopupMessage.success(e.getTimed(), e.getMsg(),
                Optional.ofNullable(e.getInitOwnerStage())
                        .orElse(AbstractApplication.getAppStage()));
    }),
    INFO("信息", (t, e) -> {
        PopupMessage.info(e.getTimed(), e.getMsg(),
                Optional.ofNullable(e.getInitOwnerStage())
                        .orElse(AbstractApplication.getAppStage()));
    }),
    WARNING("警告", (t, e) -> {
        PopupMessage.warning(e.getTimed(), e.getMsg(),
                Optional.ofNullable(e.getInitOwnerStage())
                        .orElse(AbstractApplication.getAppStage()));
    }),
    ERROR("错误", (t, e) -> {
        PopupMessage.error(e.getTimed(), e.getMsg(),
                Optional.ofNullable(e.getInitOwnerStage())
                        .orElse(AbstractApplication.getAppStage()));
    });

    private final String desc;
    private final BiConsumer<Thread, AbstractPopupException> popupCallback;


    PopupMessageTypeEnum(String desc, BiConsumer<Thread, AbstractPopupException> popupCallback) {
        this.desc = desc;
        this.popupCallback = popupCallback;
    }

    public String getDesc() {
        return this.desc;
    }

    public BiConsumer<Thread, AbstractPopupException> getPopupCallback() {
        return popupCallback;
    }

    @Override
    public String toString() {
        return this.desc;
    }
}
